home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / Laughs / Source / CLaughsApp.cp next >
Encoding:
Text File  |  1994-08-30  |  5.2 KB  |  230 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CLaughsApp.cp
  3.  *
  4.  *    Implementation of a sample application full of laughter.
  5.  *
  6.  *    This sample app is derived from a contribution originally made
  7.  *    by Paul Gee (Gee, thanks Paul!).
  8.  *
  9.  *  Copyright © 1994 NeoLogic Systems.  All rights reserved.
  10.  *
  11.  *****/
  12.  
  13. #include "NeoTypes.h"
  14. #include <stdio.h>
  15. #include CNeoMetaClassH
  16. #include CNeoDatabaseNativeH
  17. #include CNeoIDListH
  18. #include "CLaughsApp.h"
  19. #include "CLaughsDoc.h"
  20. #include "CNameIndex.h"
  21. #include "CPerson.h"
  22.  
  23. extern    OSType    gSignature;
  24.  
  25. int main(void)
  26. {
  27.     CLaughsApp    *    app;
  28.  
  29.     app = new CLaughsApp();
  30.     app->Run();
  31.     app->Exit();
  32.  
  33.     return 0;
  34. }
  35.  
  36. /***
  37.  * CLaughsApp
  38.  *
  39.  *    Initialize the application. If your application class defines its
  40.  *    own instance variables or global variables, this is a good place
  41.  *    to initialize them.
  42.  *
  43.  ***/
  44. CLaughsApp::CLaughsApp(void)
  45. #ifdef __PowerPlant__
  46.     : CNeoAppRoot(kLaughsSig, kLaughsFileType)
  47. #endif
  48. {
  49.     CNeoMetaClass *        meta;
  50.  
  51. #if defined(qNeoDebug) && !defined(__MWERKS__)
  52.     gBreakFailure = TRUE;
  53. #endif
  54.  
  55.     IApplication(kNeoExtraMasters, kNeoRainyDayFund, kNeoCriticalBalance, kNeoToolboxBalance);
  56.  
  57.     printf("Start Laughing...\n\n");
  58.         
  59.     meta = new CNeoMetaClass(kNameIndexID, kNeoNullClassID, "\pCNameIndex", CNameIndex::New, CNameIndex::KeyManager);
  60.  
  61.     meta = new CNeoMetaClass(kNeoIDListID, kNeoNullClassID, "\pCNeoIDList", CNeoIDList::New, CNeoIDList::KeyManager);
  62.  
  63.     meta = new CNeoMetaClass(kPersonID, kNeoPersistID, "\pCPerson", CPerson::New);
  64.     meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
  65.  
  66.     meta = new CNeoMetaClass(kJokerID, kPersonID, "\pCJoker", CJoker::New);
  67.     meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
  68.  
  69.     meta = new CNeoMetaClass(kJokeID, kNeoPersistID, "\pCJoke", CJoke::New);
  70.  
  71.     meta = new CNeoMetaClass(kClownID, kPersonID, "\pCClown", CClown::New);
  72.     meta->setKey(kNeoSecondaryIndex, kNameIndexID, kPersonID);
  73.  
  74.     meta = new CNeoMetaClass(kPieID, kNeoPersistID, "\pCPie", CPie::New);
  75.  
  76.     // We don't know what we want to do yet.
  77.     // Force user to choose New or Open menu item.
  78.     newWindowOnStartup = FALSE;
  79. }
  80.  
  81. /***
  82.  * SetUpFileParameters
  83.  *
  84.  *    In this routine you specify the kinds of files your application opens.
  85.  *
  86.  ***/
  87.  
  88. void CLaughsApp::SetUpFileParameters(void)
  89.  
  90. {
  91.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  92.  
  93.         /**
  94.         **    sfNumTypes is the number of file types
  95.         **    your application knows about.
  96.         **    sfFileTypes[] is an array of file types.
  97.         **    You can define up to 4 file types in
  98.         **    sfFileTypes[].
  99.         **
  100.         **/
  101.  
  102.     sfNumTypes = 1;
  103.     sfFileTypes[0] = kLaughsFileType;            /* Laughs file type */
  104.  
  105.         /**
  106.         **    Although it's not an instance variable,
  107.         **    this method is a good place to set the
  108.         **    gSignature global variable. Set this global
  109.         **    to your application's signature. You'll use it
  110.         **    to create a file (see CFile::CreateNew()).
  111.         **
  112.         **/
  113.  
  114.     gSignature = kLaughsSig;        /* set application signature */
  115. }
  116.  
  117. /***
  118.  * createDocument
  119.  *
  120.  *    The user chose New from the File menu.
  121.  *    In this method, you need to create a document and send it
  122.  *    a NewFile() message.
  123.  *
  124.  ***/
  125. CNeoDoc *CLaughsApp::createDocument(void)
  126. {
  127.     CLaughsDoc *    document = nil;
  128.  
  129.     NEOTRYTO {
  130.         /*
  131.          * Create your document.
  132.          *
  133.          * The arguments indicate whether the document is...
  134.          *    printable (FALSE),
  135.          *    a new file (TRUE),
  136.          *    remote (FALSE).
  137.          */
  138.         document = new CLaughsDoc(FALSE, TRUE, FALSE);
  139.  
  140.         /*
  141.          * Send the document a NewFile() message.
  142.          * The document will open a window, and
  143.          * set up the heart of the application.
  144.          */
  145.         document->NewFile();
  146.     }
  147.     NEOCLEANUP {
  148.         /*
  149.          * This cleanup handler gets executed whether or not a failure
  150.          * occurs.
  151.          */
  152.         if (document) {
  153.             delete document;
  154.             document = nil;
  155.         }
  156.     }
  157.     NEOENDTRYTO;
  158.  
  159.     return document;
  160. }
  161.  
  162. /***
  163.  * openDocument
  164.  *
  165.  *    The user chose Open… from the File menu.
  166.  *    In this method you need to create a document
  167.  *    and send it an OpenFile() message.
  168.  *
  169.  *    The macSFReply is a good SFReply record that contains
  170.  *    the name and vRefNum of the file the user chose to
  171.  *    open.
  172.  *
  173.  ***/
  174.  
  175. void CLaughsApp::OpenDocument(SFReply *macSFReply)
  176. {
  177.     Boolean            remote        = FALSE;
  178.     CLaughsDoc *    document    = nil;
  179.  
  180.     NEOTRY
  181.     {
  182.         // Our parent will check to see if this is a document we have already opened.
  183.         // If we find the file already open by the app, then fDocument will refer to it.
  184.         // If the file is opened but not by this app, then the parent will signal a failure.
  185.         inherited::OpenDocument(macSFReply);
  186.         if (fDocument)
  187.             return;
  188.  
  189.         /**
  190.          **    Create your document.
  191.          **
  192.          **/
  193.         document = new CLaughsDoc(this, TRUE, remote);
  194.  
  195.         /**
  196.         **    Send the document an OpenFile() message.
  197.         **    The document will open a window, open
  198.         **    the file specified in the macSFReply record,
  199.         **    and display it in its window.
  200.         **
  201.         **/
  202.         document->OpenFile(macSFReply);
  203.  
  204.         delete document;
  205.         document = nil;
  206.     }
  207.     NEOCATCH
  208.     {
  209.         /*
  210.         * This exception handler gets executed if a failure occurred
  211.         * anywhere within the scope of the TRY block above. Since
  212.         * this indicates that the document could not be opened, we
  213.         * send it a unrefer message. The exception will propagate up to
  214.         * CSwitchboard's exception handler, which handles displaying
  215.         * an error alert.
  216.         */
  217.  
  218.         if (document)
  219.             delete document;
  220.     }
  221.     NEOENDTRY;
  222. }
  223.  
  224. Boolean    CLaughsApp::Quit(void)
  225. {
  226.     running = FALSE;
  227.  
  228.     // Fini!
  229.     return TRUE;
  230. }